#ifndef _FENGINE_HEIGHT_MAP
#define _FENGINE_HEIGHT_MAP

#include "stdafx.h"
#include "CoreEngine.h"
#include "FEngineException.h"
#include <string>

namespace FEngine
{
	class Entity;

	/**
	 * Create a Map, loaded from a RAW file.
	 */
	class HeightMap : public Node
	{

		public:

			/**
			 * Constructor.
			 * @param _sizeX Size of the map.
			 * @param _sizeZ Size of the map.
			 * @param _maxHeight Height of the highest point of the map, every other point is scaled between and this point.
			 * @param _fileName RAW file using to define the height.
			 */
			HeightMap(int _sizeX, int _sizeZ, int _maxHeight, const std::string& _fileName);
			virtual ~HeightMap();
			
			/**
			 * Return the size of the map.
			 * @return Size along the X axis.
			 */
			int getSizeX() const;
			
			/**
			 * Return the size of the map.
			 * @return Size along the Z axis.
			 */
			int getSizeZ() const;

			/**
			 * Get the limits of the map.
			 * In the Vector4 containing the bounds, x and z are the limit on the X axis,
			 * y and w are the limits on the Z axis.
			 * @return Vector4 containing the bounds of the map.
			 */
			Vector4 getBounds() const;
			
			/**
			 * Get the height of the given point on the map.
			 * @param _point Point on the map.
			 * @return Height of the map under the given point.
			 */
			float getHeight(const Vector2& _point) const;

			/**
			 * Get the height of the given point on the map.
			 * @param _x Point on the X axis.
			 * @param _z Point on the Z axis. 
			 * @return Height of the map under the given point.
			 */
			float getHeight(float _x, float _z) const;
			
			virtual void update(double _elapsedTime);
			virtual void render(double _elapsedTime);


		private:
			
			int			mSizeX;
			int			mSizeZ;
			
			int			mMaxHeight;
			float*		mMapHeightArray;
			
			int			mNumberVertices;
			int			mNumberPrimitives;

			
			LPDIRECT3DVERTEXBUFFER9			mVertexBuffer;
			IDirect3DVertexDeclaration9*	mVertexDeclaration;
			LPDIRECT3DINDEXBUFFER9			mIndexBuffer;
			
			void _loadRAW(const std::string& _fileName);

	};

} // namespace FEngine

#endif
